home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / program / vol15n11.zip / CORYTD.TXT next >
Text File  |  1996-03-04  |  1KB  |  38 lines

  1. Sub CorrectYTDCalc()
  2.     Dim FirstName As String, ReplaceName As String
  3.     Dim N As Integer
  4.  
  5.     FirstName=Worksheets(1).Name
  6.     FirstName=FirstName & "!"
  7.  
  8.     For N = 3 to Worksheets.Count
  9.         Worksheets(N).Activate
  10.         ReplaceName=Worksheets(N-1).Name
  11.         ReplaceName=ReplaceName & "!"
  12.         Range("A1", Range("A1").SpecialCells(xlLastCell)).Select
  13. Selection.Replace what:=FirstName, replacement:=ReplaceName
  14.     Next N
  15. End Sub
  16.  
  17. Function YTD(CellRef) As Double
  18.     Dim rw As Integer, cl As Integer, idx As Integer
  19.     rw = CellRef.Row
  20.     cl = CellRef.Column
  21.     For idx = 1 To ActiveSheet.Index
  22.         YTD = YTD + Worksheets(idx).Cells(rw, cl).Value
  23.     Next
  24. End Function
  25.  
  26. Sub BuildFormula()
  27.     Dim CellRef As Range
  28.     Dim Address As String
  29.     
  30.     Set CellRef = Application.InputBox(prompt:= _
  31.         "Click on a cell or type the reference", _
  32.         Title:="Which cell do you want in the sum?", _
  33.         Type:=8)
  34.     Address = CellRef.Address
  35.     ActiveCell.Formula = _
  36.   "=SUM(Jan:" & ActiveSheet.Name & "!" & Address & ")"
  37. End Sub
  38.